$().ready(function() {
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/reservationRecord/manage/sendTicket",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				if (data.msg) {
					parent.layer.alert(data.msg)
				}
			}

		}
	});
}

/**
 * 全员提交
 * @returns
 */
function allsave() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/promotion/ticket/sendTicketAll",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				if (data.msg) {
					parent.layer.alert(data.msg)
				}
			}

		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules: {
			mid: {
				required: true
			},
			num: {
				required: true
			}
		},
		messages: {
			mid: {
				required: icon + "请选择会员"
			},
			num: {
				required: icon + "输入赠送数量"
			}
		}
	})
}

/**
 * 设置会员信息
 * @param memberId
 * @param memberName
 */
function loadMemberInfo(memberId, memberName) {
	$('#mids').val(memberId);
	$('#nickname').val(memberName);
	$('#name').val("");
}

/**
 * 设置订单会员信息
 * @param memberId
 * @param memberName
 */
function loadorderInfo(memberId, memberName) {
	$('#mids').val(memberId);
	$('#name').val(memberName);
	$('#nickname').val("");
}

/**
 * 会员选择
 */
function selectMember() {
	var reservationRecordId = $('#reservationRecordId').val();
	layer.open({
		id: "ticket_select_member",
		type: 2,
		title: "选择会员",
		maxmin: true,
		shadeClose: true,
		area: ['70%', '80%'],
		content: "/reservationRecord/manage/selectMember"
	})
}

/**
 * 订单商品页面
 */
function selectorder() {
	layer.open({
		id: "ticket_select_order",
		type: 2,
		title: "选择订单",
		maxmin: true,
		shadeClose: true,
		area: ['100%', '100%'],
		content: "/promotion/ticket/toOrderProductPage"
	})
}